package com.mmf.web;

import com.mmf.dto.ResponseModel;
import com.mmf.model.User;
import com.mmf.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by MMF on 2017/6/14.
 */
@Controller
@RequestMapping("/")
public class IndexController extends BaseController{
    @Resource
    private IUserService userService;
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    private String login() {
        return "login";
    }
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    private String index() {

//        request.setAttribute("sb","毛美芳");
        return "index";
    }

    /**
     * 商品列表
     * @return
     */
    @RequestMapping(value = "/GoodsList", method = RequestMethod.GET)
    private String GoodsList() {

//        request.setAttribute("sb","毛美芳");
        return "GoodsList";
    }

    /**
     * 添加商品
     * @return
     */
    @RequestMapping(value = "/GoodsAdd", method = RequestMethod.GET)
    private String GoodsAdd() {
        return "GoodsAdd";
    }


    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public Object login(String name, String password) {
        User user = userService.login(name,password);
        if (user == null){
            return new ResponseModel(-1,"登录失败");
        }
        request.getSession().setAttribute("loginUser",user);
        return new ResponseModel(0,"登录成功");
    }

}
